    layui.use(['layer', 'form', 'table', 'admin', 'ax'], function () {
    var $ = layui.$;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;

    /**
     * 系统管理--规格管理
     */
    var shopAttr = {
        tableId: "roleTable",    //表格id
        condition: {
            roleName: ""
        }
    };



    /**
     * 弹出添加
     */

    shopAttr.openAddRole = function () {
        admin.putTempData('formOk', false);
        top.layui.admin.open({
            type: 2,
            title: '添加规格名称',
            content: Feng.ctxPath + '/tbattribute/tbattribute_add',
            end: function () {
                admin.getTempData('formOk') && table.reload(shopAttr.tableId);
            }
        });
    };
        /**
         * 弹出添加规格值
         * @param data
         */
    shopAttr.openAddRole2 = function (data) {
        admin.putTempData('formOk', false);
        top.layui.admin.open({
            type: 2,
            title: '添加规格值',
            content: Feng.ctxPath + '/tbattribute/tbattribute_edit?id='+ data.id,
            end: function () {
                admin.getTempData('formOk') && table.reload(shopAttr.tableId);
            }
        });
    };



    /**
     * 点击编辑
     *
     * @param data 点击按钮时候的行数据
     */
    shopAttr.onEditRole = function (data) {
        admin.putTempData('formOk', false);
        top.layui.admin.open({
            type: 2,
            title: '编辑规格值',
            content: Feng.ctxPath + '/tbattribute/role_edit?attributeId=' + data.attributeId,
            end: function () {
                admin.getTempData('formOk') && table.reload(shopAttr.tableId);
            }
        });
    };

    /**
     * 点击删除
     *
     * @param data 点击按钮时候的行数据  "/tbattribute/remove/"+data.id+"/"+data.name+"/"+data.value
     */
  shopAttr.onDeleteRole = function (data) {
           var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/tbattribute/remove?id="+data.id, function () {
                Feng.success("删除成功!");
                table.reload(shopAttr.tableId);
            }, function (data) {
                Feng.error("删除成功!");
                table.reload(shopAttr.tableId);
            });
                ajax.set(data.field);
                ajax.start();
        };
                Feng.confirm("是否删除规格 " + data.name + data.value, operation);
    };
    // 渲染表格
    var tableResult = table.render({
        elem: '#' + shopAttr.tableId,
        url: Feng.ctxPath + '/tbattribute/tbalist',
        page: false,
        height: "full-158",
        cellMinWidth: 100,
        parseData:function(list){
            console.log(list);
            return{
                "code":0,
                "msg":"",
                "count":1000,
                "data":list
            };
        },
        cols:[[
            {field: 'id', sort: true, title: '规格类型Id'},
            {field: 'name', sort: true, title: '规格名称'},
            {field: 'value',sort: true, title: '规格值'},
            {align: '', toolbar: '#tableBar', title: '操作', minWidth: 200}
        ]]

    });

//templet: '<div>{{(d.tbAttributeValues[0].attributeId)}}</div>'

    // 添加按钮点击事件
    $('#btnAdd').click(function () {
        shopAttr.openAddRole();
    });


   // 工具条点击事件
   table.on('tool(' + shopAttr.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        if (layEvent === 'edit') {
            shopAttr.onEditRole(data);
        } else if (layEvent === 'delete') {
            shopAttr.onDeleteRole(data);
        } else if (layEvent === 'add') {
            shopAttr.openAddRole2(data);
        }
    });
});
